package com.elitesland.system.entity;

import com.elitesland.core.base.BaseModel;
import com.elitesland.system.annotation.Comment;
import com.elitesland.system.convert.BooleanToIntegerConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;

/**
 * <pre>
 * [功能说明]
 * </pre>
 *
 * @author Mir
 * @date 2020/6/15
 */
@Entity
@Table(name = "sys_role")
@org.hibernate.annotations.Table(appliesTo = "sys_role", comment = "系统角色表")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "系统角色表", description = "系统角色表")
@DynamicUpdate
public class SysRoleDO extends BaseModel implements Serializable {
    private static final long serialVersionUID = 5152159757116510744L;

    @ApiModelProperty(value = "角色代码")
    @Comment("角色代码")
    @Column(length = 16, nullable = false, unique = true)
    private String code;

    @ApiModelProperty(value = "角色名称")
    @Comment("角色名称")
    @Column(length = 32, nullable = false)
    private String name;

    @ApiModelProperty(value = "是否启用")
    @Comment("是否启用")
    @Column()
    @Convert(converter = BooleanToIntegerConverter.class)
    Boolean enabled;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof SysRoleDO)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        SysRoleDO entity = (SysRoleDO) o;
        return getId().equals(entity.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }
}
